/**
 * 城市默认分类系数编辑
 * @author linfeng
 * @since 2019/08/24 16:06
 */
layui.define(['form', 'layedit', 'laydate'], function (exports) {
    let $ = layui.$;
    let form = layui.form;

    let laydate = layui.laydate;

    let effectiveDateObj = {
        elem: '#effectiveDate',
        type: 'date',
        btns: ['clear', 'confirm'],
        min: 1
    };

    laydate.render(effectiveDateObj);

    form.render(null, "zmn-form");
    // 提交
    form.on('submit(zmn-form-submit)', function (obj) {

        if (obj.field.cityRatio != null && obj.field.cityRatio != undefined) {
            if (!valueVerify(obj.field.cityRatio)) {
                return false;
            }

            parent.submitChannelCityBatchRatio(json.channelId, obj.field.cityRatio,obj.field.cityMeterRatio, json.bizType, json.priceType, obj.field.effectiveDate);
        }

        cancel();
        return false;
    });

    //点击取消
    $(document).on('click', '#cancel', function () {
        let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
    });

    //对外暴露的接口
    exports('channel_city_batch_price_ratio_edit', {});
});

function valueVerify(value) {
    var reg = /^\d+(\.\d{1,2})?$/;

    if (value == "") {
        return true;
    }

    if (isNaN(value)) {
        layer.alert("请输入正确的数字");
        return false;
    }

    // if (value == '0' || value == '0.0' || value == '0.00') {
    //     return true;
    // }

    if (!reg.test(value)) {
        layer.alert("请输入整数或者1到2位小数");
        return false;
    }

    if ((parseFloat(0.6) <= parseFloat(value) && parseFloat(3.0) >= parseFloat(value))) {
    } else {
        layer.alert("系数值不符合规定,系数值范围0.6~3.0");
        return false;
    }

    return true;
}

function cancel() {
    let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index);
}
